<?php

namespace app\admin\controller;


class About extends Base
{
    //颐投介绍
    public function about()
    {
        if (request()->isAjax()){
            $about = model('common/About') -> find(input('post.id'));
            $about -> content = input('post.content');
            $result = $about -> save();
            if ($result){
                $this -> success('更新成功！','admin/about/about');
            } else {
                $this -> error('更新失败');
            }
        }
        $about = model('common/About') -> find();
        $data = [
            'about' => $about
        ];
        $this -> assign($data);
        return view();
    }

    //留学通列表
    public function school()
    {
        $school = model('common/School') -> paginate(10);
        $data = [
            'school' => $school
        ];
        $this -> assign($data);
        return view('about/school');
    }

    //留学通添加
    public function school_add()
    {
        if (request()->isajax()) {
            $data = input('post.');
            $result = model('common/School') -> school_add($data);
            if ($result == 1){
                $this -> success('添加成功！','admin/about/school');
            } else {
                $this -> error($result);
            }
        }
        return view();
    }

    //留学通编辑
    public function school_edit()
    {
        if (request()->isAjax()){
            $result = model('common/School') -> school_edit(input('post.'));
            if ($result == 1){
                $this -> success('更新成功！','admin/about/school');
            } else {
                $this -> error($result);
            }
        }
        $school = model('common/School')->find(input('id'));
        $data = [
          'school' => $school
        ];
        $this -> assign($data);
        return view();
    }

    //留学通删除
    public function school_del()
    {
        $school = model('common/School') -> find(input('post.id'));
        $result = $school -> delete();
        if ($result){
            $this -> success('删除成功！','admin/about/school');
        } else {
            $this -> error('删除失败！');
        }
    }

    //留学通状态控制
    public function school_status()
    {
        if (request()-> isAjax()){
            $result = model('common/School') -> school_status(input('post.'));
            if ($result == 1){
                $this -> success('操作成功！','admin/about/school');
            } else {
                $this -> error($result);
            }
        }
    }

    //联系我们
    public function content()
    {
        $con = model('common/Content') -> paginate(10);
        $data = [
            'con' => $con
        ];
        $this -> assign($data);
        return view();
    }

    //联系我们添加
    public function content_add()
    {
        if (request()->isAjax()){
            $data = input('post.');
            $result = model('common/Content') -> content_add($data);
            if ($result == 1){
                $this -> success('添加成功！','admin/about/content');
            } else {
                $this -> error($result);
            }
        }
        return view();
    }

    //联系我们编辑
    public function content_edit()
    {
        if (request()->isAjax()){
            $result = model('common/Content') -> content_edit(input('post.'));
            if ($result == 1){
                $this -> success('更新成功！','admin/about/content');
            } else {
                $this -> error($result);
            }
        }
        $con = model('common/Content') -> find(input('id'));
        $data = [
            'con' => $con
        ];
        $this -> assign($data);
        return view();
    }

    //联系我们删除
    public function content_del()
    {
        if (request()->isAjax()){
            $con = model('common/Content') -> find(input('post.id'));
            $result = $con -> delete();
            if ($result){
                $this -> success('删除成功！','admin/about/content');
            } else {
                $this -> error('删除失败！');
            }
        }
    }

    //联系我们状态控制
    public function content_status()
    {
        if (request()->isAjax()){
            $data=input('post.');
            $result = model('common/Content') -> content_status($data);
            if ($result == 1){
                $this -> success('操作成功！','admin/about/content');
            } else {
                $this -> error($result);
            }
        }
    }
}
